import request from '@/utils/request'

// 销售退货订单API
export const salesReturnApi = {
  // 新增退货订单
  addReturnOrder(data) {
    return request({
      url: '/api/sales/return-order/add',
      method: 'post',
      data
    })
  },

  // 删除退货订单
  deleteReturnOrder(id) {
    return request({
      url: `/api/sales/return-order/delete/${id}`,
      method: 'delete'
    })
  },

  // 更新退货订单
  updateReturnOrder(data) {
    return request({
      url: '/api/sales/return-order/update',
      method: 'put',
      data
    })
  },

  // 查询退货订单详情
  getReturnOrderDetail(id) {
    return request({
      url: `/api/sales/return-order/detail/${id}`,
      method: 'get'
    })
  },

  // 分页查询退货订单
  getReturnOrderPage(params) {
    return request({
      url: '/api/sales/return-order/page',
      method: 'post',
      data: params
    })
  },

  // 分页查询退货订单 (GET方式)
  getReturnOrderPageGet(params) {
    return request({
      url: '/api/sales/return-order/page',
      method: 'get',
      params
    })
  },

  // 提交审核
  submitForAudit(id) {
    return request({
      url: `/api/sales/return-order/submit/${id}`,
      method: 'post'
    })
  },

  // 审核退货订单
  auditReturnOrder(id, auditResult, auditOpinion, auditorId) {
    return request({
      url: '/api/sales/return-order/audit',
      method: 'post',
      params: {
        id,
        auditResult,
        auditOpinion,
        auditorId
      }
    })
  },

  // 完成退货订单
  completeReturnOrder(id) {
    return request({
      url: `/api/sales/return-order/complete/${id}`,
      method: 'post'
    })
  },

  // 根据原销售订单ID查询退货单列表
  getReturnOrdersByOrderId(orderId) {
    return request({
      url: `/api/sales/return-order/by-order/${orderId}`,
      method: 'get'
    })
  },

  // 生成退货单编号
  generateReturnNo() {
    return request({
      url: '/api/sales/return-order/generate-no',
      method: 'get'
    })
  },

  // 检查是否可以删除
  canDelete(id) {
    return request({
      url: `/api/sales/return-order/can-delete/${id}`,
      method: 'get'
    })
  },

  // 检查是否可以编辑
  canEdit(id) {
    return request({
      url: `/api/sales/return-order/can-edit/${id}`,
      method: 'get'
    })
  }
}
